<h2 class="contentTitle">编辑资讯</h2>
<form action="<?php echo SITE_URL . 'index.php?c='.$controller.'&a=ajaxEdit';?>" method="post" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone)">
    <div class="pageContent">
        <div layouth="97" class="pageFormContent nowrap" style="height: 376px; overflow: auto;">
            <dl>
                <dt>资讯名称：</dt>
                <dd>
                    <input type="text" name="title" size="60" class="required textInput valid" value="<?php echo $info['title']; ?>">
                    <input type="hidden" name="new_id" value="<?php echo $info['new_id']; ?>">
                    <span class="inputInfo">填写资讯名称</span>
                </dd>
            </dl>
            <dl>
                <dt>资讯标签：</dt>
                <dd>
                    <input type="text" name="tag" size="60" class="required textInput valid" value="<?php echo $info['tag']; ?>">
                    <input type="hidden" name="old_tag" value="<?php echo $info['tag']; ?>">
                    <span class="inputInfo">多个标签以","分割，站内搜索用</span>
                </dd>
            </dl>
            <dl>
                <dt>资讯类别：</dt>
                <dd>
                    <select class="combox" name="category_id">
                        <?php
                        foreach($category_list as $k=>$v){
                            ?>
                            <option value="<?php echo $k; ?>" <?php echo $info['category_id'] == $k ? 'selected="true"' : ''; ?>><?php echo $v; ?></option>
                        <?php
                        }
                        ?>
                    </select>
                    <input type="hidden" name="old_category_id" value="<?php echo $info['category_id']; ?>">
                    <span class="inputInfo">请选择类别</span>
                </dd>
            </dl>
            <dl>
                <dt>资讯来源：</dt>
                <dd>
                    <select class="combox" name="source_id">
                        <?php
                        foreach($source_list as $k=>$v){
                            ?>
                            <option value="<?php echo $k; ?>" <?php echo $info['source_id'] == $k ? 'selected="true"' : ''; ?>><?php echo $v; ?></option>
                        <?php
                        }
                        ?>
                    </select>
                    <span class="inputInfo">请选择来源</span>
                </dd>
            </dl>
            <dl>
                <dt>资讯状态：</dt>
                <dd>
                    <select class="combox" name="status">
                        <?php
                        foreach($status_list as $k=>$v){
                            ?>
                            <option value="<?php echo $k; ?>" <?php echo $info['status'] == $k ? 'selected="true"' : ''; ?>><?php echo $v; ?></option>
                        <?php
                        }
                        ?>
                    </select>
                    <span class="inputInfo">资讯显示状态</span>
                </dd>
            </dl>
            <dl>
                <dt>关键词组：</dt>
                <dd>
                    <textarea rows="2" cols="60" name="keywords" id="keywords" class="required textInput"><?php echo $info['keywords']; ?></textarea>
                    <span class="inputInfo">页面显示时的关键词</span>
                </dd>
            </dl>
            <dl>
                <dt>资讯描述：</dt>
                <dd>
                    <textarea rows="2" cols="60" name="description" id="description" class="required textInput"><?php echo $info['description']; ?></textarea>
                    <span class="inputInfo">页面显示时的描述信息</span>
                </dd>
            </dl>
            <dl>
                <dt>资讯摘要：</dt>
                <dd>
                    <textarea rows="2" cols="60" name="summary" id="summary" class="required textInput"><?php echo $info['summary']; ?></textarea>
                    <span class="inputInfo">用于列表页显示资讯用</span>
                </dd>
            </dl>
            <dl>
                <dt>资讯缩图：</dt>
                <dd>
                    <input id="file_upload" type="file" name="picture"/>
                    <span class="inputInfo">上传该新闻的缩略图，注意图片选择要具有吸引力</span>
                    <img id= "curr_picture" src="<?php echo $info['picture']; ?>" style="border: 1px solid #000000">
                    <input type="hidden" name="picture" value="<?php echo $info['picture']; ?>">

                </dd>
            </dl>
            <dl>
                <dt>资讯内容：</dt>
                <dd style="width: 700px">
                    <textarea name="content" id="content" style="height: 350px; width: 700px;"><?php echo $info['content']; ?></textarea>
                </dd>
            </dl>
        </div>
        <div class="formBar">
            <ul>
                <li><div class="buttonActive"><div class="buttonContent"><button type="submit">确认</button></div></div></li>
                <li><div class="button"><div class="buttonContent"><button class="close" type="button">关闭</button></div></div></li>
            </ul>
        </div>
    </div>
</form>
<script type="text/javascript">
    $('input[name=title]').die().live('blur',function(){
        $.get('<?php echo SITE_URL . 'index.php?c='.$controller.'&a=getTags&title=';?>'+$(this).val(), function(json){
            $.each(json,function(i,v){
                $('._tag').append('<a href="###">'+v+'</a>&nbsp;&nbsp;');
            });

            $('._tag a').each(function(){
                var _self = $(this);
                _self.die().live('click',function(){
                    var tag_show = $('input[name=tag]').val();

                    var tag_arr = tag_show.split(',');

                    if($.inArray(_self.text(),tag_arr) == -1){
                        if(tag_show == '' || tag_show == null){
                            $('input[name=tag]').val(_self.text());
                        }else{
                            $('input[name=tag]').val($('input[name=tag]').val()+','+_self.text());
                        }
                    }
                });
            });
        });
    });

    //动态加载 Kindeditor 文本编辑器
    var  content ;
    $.getScript('<?php echo SITE_URL; ?>/theme/js/kindeditor-4.1.7/kindeditor-min.js', function() {
        KindEditor.basePath = '<?php echo SITE_URL."/theme/js/kindeditor-4.1.7/"; ?>';
        content = KindEditor.create('textarea[name="content"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: '<?php echo SITE_URL . 'index.php?c='.$controller.'&a=newPictureUpload&type=new';?>',
            fileManagerJson: '<?php echo SITE_URL . 'index.php?c='.$controller.'&a=newDirPicture';?>',
            allowFileManager: true,
            //经测试，下面这行代码可有可无，不影响获取textarea的值
            //afterCreate: function(){this.sync();}
            //下面这行代码就是关键的所在，当失去焦点时执行 this.sync();
            afterBlur: function () { this.sync(); }
        });
    });

    //动态加载上传插件
    <?php $timestamp = time();?>
    $(function() {
        $('#file_upload').uploadify({
            'onInit': function(){},
            'formData'     : {
                'type' : 'add',
                'timestamp' : '<?php echo $timestamp;?>',
                'token'     : '<?php echo md5(MD5_CODE . $timestamp);?>'
            },
            'simUploadLimit':1,
            'swf'      : '<?php echo DWZ_URL; ?>uploadify/scripts/uploadify.swf',
            'uploader' : '<?php echo SITE_URL . 'index.php?c='.$controller.'&a=newPictureUpload';?>',
            'buttonText' : '上传图片',
            'fileSizeLimit':'2018KB',
            'fileTypeDesc':'*.jpg;*.jpeg;*.gif;*.png;',
            'fileTypeExts':'*.jpg;*.jpeg;*.gif;*.png;',
            'auto':true,
            'multi':false,
            'onUploadError' : function(file,errorCode,errorMsg,errorString,swfuploadifyQueue){
                //alert(errorMsg);//上传文件出错是触发（每个出错文件触发一次）
                alertMsg.info(errorMsg);
            },
            'onUploadSuccess':function(file,data,response){

                var data_str = data.replace("\n\n","");
                var error_str = data_str.substring(0,5);

                if(error_str == "error"){
                    alertMsg.error('上传图片异常，请联系管理员检查！');
                }else{
                    $('#curr_picture').attr('src',data_str+'?'+Math.random()).attr('original',data_str);
                    $('input[name=picture]').val(data_str);
                }
            },
            'onSelect': function (event, queueID, fileObj)
            {
                $("#file_upload").uploadify('settings','formData',{curr_picture:$('input[name=picture]').val()})
            }
        });
    });
</script>